package previous.Test_0224;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
public class Solution {
    //二进制求和
    public String addBinary(String a, String b) {
          StringBuilder stringBuilder=new StringBuilder();
          //从末尾开始
          int c1=a.length()-1;
          int c2=b.length()-1;
          int t=0;
          String ret;
          //两数相加
        //要t在最后也不等于0的情况下
          while(c1>=0 || c2>=0 ||t!=0){
              //记得减去‘0’；
          if(c1>=0){
              t+=a.charAt(c1)-'0';
              c1--;
          }
           if(c2>=0){
              t+=b.charAt(c2)-'0';
              c2--;
           }
           //要进行强转
           stringBuilder.append((char)('0'+(char)(t%2)));
           t/=2;
          }
         stringBuilder.reverse();
          //返回字符串
          return stringBuilder.toString();
    }
}
